/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sun.Facade;

import com.sun.Entity.Shippingorder;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Trasheur
 */
@Stateless
public class ShippingorderFacade implements ShippingorderFacadeLocal {

    @PersistenceContext
    private EntityManager em;

    public void create(Shippingorder shippingorder) {
        em.persist(shippingorder);
    }

    public void edit(Shippingorder shippingorder) {
        em.merge(shippingorder);
    }

    public void remove(Shippingorder shippingorder) {
        em.remove(em.merge(shippingorder));
    }

    public Shippingorder find(Object id) {
        return em.find(Shippingorder.class, id);
    }

    public List<Shippingorder> findAll() {
        return em.createQuery("select object(o) from Shippingorder as o").getResultList();
    }

    public List<Shippingorder> findAvailability(Date estimatedshippeddate, Date shippeddate) {
     
        Query cq = em.createNamedQuery("Shippingorder.findByAvailability");
        
        // cq.setParameter("estimatedshippeddate", estimate.get(Calendar.YEAR) + "-" + estimate.get(Calendar.MONTH) + "-" + estimate.get(Calendar.DAY_OF_MONTH));
        // cq.setParameter("shippeddate", shipped.get(Calendar.YEAR) + "-" + shipped.get(Calendar.MONTH) + "-" + shipped.get(Calendar.DAY_OF_MONTH));
        cq.setParameter("estimatedshippeddate", estimatedshippeddate);
        cq.setParameter("shippeddate", shippeddate);
        System.out.println(estimatedshippeddate);
        System.out.println(shippeddate);

        return cq.getResultList();
    }
}
